﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using eschoolBO;

namespace ESCHOOL.admin
{
    public partial class WebForm11 : System.Web.UI.Page
    {
        user_types ut = new user_types();
        protected void Page_Load(object sender, EventArgs e)
        {
            btnupdate.Visible = false;
            if (!IsPostBack)
            {
                DataTable dt = ut.GetRecords(-99, "", false, " and ");
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }

        protected void btninsert_Click(object sender, EventArgs e)
        {
            ut.user_type_id=-99;
            ut.user_type=tbusertype.Text;
            ut.isdeleted=false;
            ut.SaveRecords();
            Response.Redirect("~/admin/UserType.aspx");
        }

        protected void btndelete_Command(object sender, CommandEventArgs e)
        {
            if(e.CommandName=="Delete")
            {
                DataTable dt=ut.GetRecords(Convert.ToInt64(e.CommandArgument),"",false," and ");
                ut.user_type_id=Convert.ToInt64(dt.Rows[0]["user_type_id"].ToString());
                ut.user_type=dt.Rows[0]["user_type"].ToString();
                ut.isdeleted=true;
                ut.SaveRecords();
                Response.Redirect("~/admin/UserType.aspx");
            }

        }

        protected void btnedit_Command(object sender, CommandEventArgs e)
        {
            btninsert.Visible=false;
            btnupdate.Visible=true;
            DataTable dt=ut.GetRecords(Convert.ToInt64(e.CommandArgument),"",false," and ");
            tbuserid.Text = Convert.ToString(dt.Rows[0]["user_type_id"].ToString());
            tbusertype.Text=dt.Rows[0]["user_type"].ToString();
        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            ut.user_type_id = Convert.ToInt64(tbuserid.Text);
            ut.user_type=tbusertype.Text;
            ut.isdeleted=false;
            ut.SaveRecords();
            Response.Redirect("~/admin/UserType.aspx");
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

           
        
     }

 }
